package com.electric.flinkcep.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * 预测电力负荷数据模型
 * 对应 predict_data 主题的消息格式
 */
public class PredictData implements Serializable {
    
    @JsonProperty("timestamp")
    private String timestamp;
    
    @JsonProperty("predicted_load")
    private double predictedLoad;

    @JsonProperty("request_id")
    private String requestId;

    @JsonProperty("model_info")
    private ModelInfo modelInfo;

    @JsonProperty("sequence_id")
    private int sequenceId;

    // 默认构造函数
    public PredictData() {
    }

    // 全参构造函数
    public PredictData(String timestamp, double predictedLoad, String requestId,
                      ModelInfo modelInfo, int sequenceId) {
        this.timestamp = timestamp;
        this.predictedLoad = predictedLoad;
        this.requestId = requestId;
        this.modelInfo = modelInfo;
        this.sequenceId = sequenceId;
    }

    
    /**
     * 获取时间戳的毫秒值
     */
    public long getTimestampMillis() {
        try {
            LocalDateTime dateTime = LocalDateTime.parse(timestamp, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
            return dateTime.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli();
        } catch (Exception e) {
            return System.currentTimeMillis();
        }
    }
    
    // Getter和Setter方法
    public String getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }
    
    public double getPredictedLoad() {
        return predictedLoad;
    }

    public void setPredictedLoad(double predictedLoad) {
        this.predictedLoad = predictedLoad;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public ModelInfo getModelInfo() {
        return modelInfo;
    }

    public void setModelInfo(ModelInfo modelInfo) {
        this.modelInfo = modelInfo;
    }

    public int getSequenceId() {
        return sequenceId;
    }
    
    public void setSequenceId(int sequenceId) {
        this.sequenceId = sequenceId;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PredictData that = (PredictData) o;
        return Double.compare(that.predictedLoad, predictedLoad) == 0 &&
               sequenceId == that.sequenceId &&
               Objects.equals(timestamp, that.timestamp);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(timestamp, predictedLoad, sequenceId);
    }
    
    @Override
    public String toString() {
        return "PredictData{" +
                "timestamp='" + timestamp + '\'' +
                ", predictedLoad=" + predictedLoad +
                ", requestId='" + requestId + '\'' +
                ", modelInfo=" + modelInfo +
                ", sequenceId=" + sequenceId +
                '}';
    }
}